<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <script type="text/javascript">
  		var path = "<%=basePath%>";
  		//公共参数
  		var shareAreaUID = "<s:property value='shareAreaUID' />";
  	</script>
    <title>Shared area Heat User setting</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>basic/css/content.css">
	<link rel="stylesheet" href="<%=basePath%>resources/tree/css/org_style.css" />
	<jsp:include page="/resources/resource-refer/component-dynamictree-reference.jsp" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
  </head>
  <script type="text/javascript">
  	$(function(){
		$("input[name='submit']").click(function(){
			submitAreaArchitectConfig();
		});
	});
	
	function submitAreaArchitectConfig() {
		if(shareAreaUID==null || shareAreaUID=="") {
			Dialog.alert("Please select the shared area to be edited！");
			return;
		}
		var selectedNodeIDs = tree.getAllCheckedBranches();
		var selectedIDList = selectedNodeIDs.split(",");
		//热用户ID列表
		var roomIDList = "";
		for(var index=0; index<selectedIDList.length; index++) {
			var nodeType = tree.getUserData("nodeType", selectedIDList[index]);
			if(nodeType == "room") {
				roomIDList += selectedIDList[index];
				roomIDList += ",";
			}
		}
		if(roomIDList.lastIndexOf(",") == roomIDList.length-1) {
			roomIDList = roomIDList.substring(0, roomIDList.length-1);
		}
		$.post(path+"beshs/heatRoomActionJson!saveAreaRoomArchitect.do?date="+new Date(), {
			shareAreaUID: shareAreaUID,
			roomIDList: roomIDList
		}, function(data) {
			var json = $.parseJSON(data);
			if(json.success) {
				Dialog.alert("Successful Operation！");
			} else {
				Dialog.alert("System error, please contact adminitrator！");
			}
		})
	}
  </script>
  <body style="height: 100%;width: 100%;overflow: no;">
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
   	<s:if test="superManager.contains(#session.user.userID) 
			|| loginUserRoleIDList.contains(sysadmin) 
			|| loginUserRoleIDList.contains(sysShareManager)">
		<tr>
		    <td style="border:none;">
		    	<input name="submit" type="button" value="Save" class="s_btn" style="margin-left: 3px"/>
		    </td>
		</tr>
	</s:if>
		<tr>
			<td style="border:none;" id="nodeManage_tree"></td>
		</tr>
    </table>
	<script type="text/javascript">
		var tree = new dhtmlXTreeObject("nodeManage_tree","100%","100%",0);
		tree.setImagePath(path+"resources/tree/org_tree_img/");
		$.getJSON(path+"beshs/heatRoomActionJson!queryRelatedRoomArchitect.do?date="+new Date(),{
			shareAreaUID: shareAreaUID
		}, function(data){
			tree.loadJSONObject(data);
		});
		//设置树节点复选
		tree.enableCheckBoxes(true);
		tree.enableThreeStateCheckboxes(1);
		tree.setOnCheckHandler(function(nodeID) {
			tree.openItem(nodeID);
		});
		//子节点数据异步加载
		tree.attachEvent("onOpenEnd",function(nodeID, event){
			var nodeType = tree.getUserData("nodeType",nodeID);
			//event是记录展开/合拢动作，-1为合拢  还有0、1；
			if(event != -1) {
				tree.deleteChildItems(nodeID);//删除当前节点下的所有子节点
				$.getJSON(path+"beshs/heatRoomActionJson!queryRelatedRoomArchitect.do?date="+new Date(), {
					shareAreaUID: shareAreaUID,
					nodeID: nodeID,
					nodeType: nodeType
				}, function(data){
					tree.loadJSONObject(data);
				});
			}
		});
	</script>
  </body>
</html>
